Implement bookmark reordering, at least the core
authorFederico Mena Quintero <federico@gnome.org>
Tue, 11 Sep 2012 20:17:03 +0000 (15:17 -0500)
committerFederico Mena Quintero <federico@gnome.org>
Tue, 11 Sep 2012 20:17:03 +0000 (15:17 -0500)
The drag-and-drop part is missing; that still needs de-nautilus-ifying.

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
gtk/gtkbookmarksmanager.c
gtk/gtkbookmarksmanager.h
gtk/gtkplacessidebar.c

index aa55dac9f5205c9e3ed706d25403d8cdfa205b2a..4cd46f9a18a140a68f48f8727f150c2591dea84f 100644 (file)
@@ -382,6 +382,55 @@ _gtk_bookmarks_manager_remove_bookmark (GtkBookmarksManager *manager,
   return TRUE;
 }
 
+gboolean
+_gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
+                                        GFile               *file,
+                                        gint                 new_position,
+                                        GError             **error)
+{
+  GSList *link;
+  GFile *bookmarks_file;
+
+  g_return_val_if_fail (manager != NULL, FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (!manager->bookmarks)
+    return FALSE;
+
+  link = find_bookmark_link_for_file (manager->bookmarks, file);
+  if (link)
+    {
+      GtkBookmark *bookmark = link->data; 
+
+      manager->bookmarks = g_slist_remove_link (manager->bookmarks, link);
+      g_slist_free_1 (link);
+
+      manager->bookmarks = g_slist_insert (manager->bookmarks, bookmark, new_position);
+    }
+  else
+    {
+      gchar *uri = g_file_get_uri (file);
+
+      g_set_error (error,
+                  GTK_FILE_CHOOSER_ERROR,
+                  GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
+                  "%s does not exist in the bookmarks list",
+                  uri);
+
+      g_free (uri);
+
+      return FALSE;
+    }
+
+  bookmarks_file = get_bookmarks_file ();
+  save_bookmarks (bookmarks_file, manager->bookmarks);
+  g_object_unref (bookmarks_file);
+
+  notify_changed (manager);
+
+  return TRUE;
+}
+
 gchar *
 _gtk_bookmarks_manager_get_bookmark_label (GtkBookmarksManager *manager,
                                           GFile               *file)
index 8c00052f5e52c2d06c5bd3b0d2596ebb05a5b420..005a315e85bef18e7b79b646345c7af42a74069c 100644 (file)
@@ -64,6 +64,11 @@ gboolean _gtk_bookmarks_manager_remove_bookmark (GtkBookmarksManager *manager,
                                                 GFile               *file,
                                                 GError             **error);
 
+gboolean _gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
+                                                 GFile               *file,
+                                                 gint                 new_position,
+                                                 GError             **error);
+
 gchar * _gtk_bookmarks_manager_get_bookmark_label (GtkBookmarksManager *manager,
                                                   GFile               *file);
 
index 347776496dac4255c4047d19d41c4668e4b6150b..1f9c30a2006b440476e1559261db78163cfe37ef 100644 (file)
@@ -32,6 +32,8 @@
  *
  * * Fix FIXMEs
  *
+ * * Grep for "NULL-GError" and see if they should be taken care of
+ *
  * * Nautilus needs to use gtk_places_sidebar_set_uri() instead of built-in
  *   notification from the NautilusWindowSlot.
  */
@@ -1437,10 +1439,9 @@ static void
 reorder_bookmarks (GtkPlacesSidebar *sidebar,
                   int                   new_position)
 {
-#if DO_NOT_COMPILE
        GtkTreeIter iter;
-       PlaceType type;
-       int old_position;
+       char *uri;
+       GFile *file;
 
        /* Get the selected path */
        if (!get_selected_iter (sidebar, &iter)) {
@@ -1448,19 +1449,14 @@ reorder_bookmarks (GtkPlacesSidebar *sidebar,
        }
 
        gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
-                           PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
-                           PLACES_SIDEBAR_COLUMN_INDEX, &old_position,
+                           PLACES_SIDEBAR_COLUMN_URI, &uri,
                            -1);
 
-       if (type != PLACES_BOOKMARK ||
-           old_position < 0 ||
-           old_position >= nautilus_bookmark_list_length (sidebar->bookmarks)) {
-               return;
-       }
+       file = g_file_new_for_uri (uri);
+       _gtk_bookmarks_manager_reorder_bookmark (sidebar->bookmarks_manager, file, new_position, NULL); /* NULL-GError */
 
-       nautilus_bookmark_list_move_item (sidebar->bookmarks, old_position,
-                                         new_position);
-#endif
+       g_object_unref (file);
+       g_free (uri);
 }
 
 static void